package com.service.impl;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.dao.mapper.PomrDao;
import com.domain.Pomr;
import com.service.PomrService;
import com.utils.ObjectUtils;
import com.utils.report.ReadExcel;


@Service(value="pomrsUploadService")
public class PomrsUploadService {
	
	@Autowired
	private PomrDao pomrDao;

	@Autowired
	PomrService pomrService;
	
	private String ocode;
	
	
	public void setOcode(String ocode) {
		this.ocode = ocode;
	}
	
	public boolean batchImport(String name,MultipartFile file,int ocode1){
        boolean b = false;
        //创建处理EXCEL
        ReadExcel readExcel=new ReadExcel();
        //解析excel，获取客户信息集合。
        List<Map<String,Object>> pomrList = readExcel.getExcelInfo(name ,file);

        if(pomrList != null){
            b = true;
        }
        
       //添加在数据库
        for(Map<String,Object> map:pomrList){
        	Pomr pomr = new Pomr();
        	pomr.setBrdh(ObjectUtils.getStrVal(map.get("brdh")));
        	pomr.setFqxm(ObjectUtils.getStrVal(map.get("fqxm")));
        	pomr.setHjdwyh(ObjectUtils.getStrVal(map.get("hjdwyh")));
        	pomr.setHjzz(ObjectUtils.getStrVal(map.get("hjzz")));
        	pomr.setHyzk(1);
        	pomr.setJdah(0);
        	pomr.setJdjg(ObjectUtils.getIntVal(map.get("jdjg").toString()));
        	pomr.setJdr(1);
        	try {
				pomr.setJdsj(ObjectUtils.getDateVal(map.get("jdsj").toString()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	pomr.setJhrxm(ObjectUtils.getStrVal(map.get("jhrxm").toString()));
        	
        	int newJkdah = pomrService.getNewJkdah(ocode1);
        	pomr.setJkdah(newJkdah);
        	pomr.setJtdh(ObjectUtils.getStrVal(map.get("jtdh")));
        	pomr.setJzlx(1);//
        	pomr.setLxrdh(ObjectUtils.getStrVal(map.get("lxrdh")));
        	pomr.setLxrxm(ObjectUtils.getStrVal(map.get("lxrxm")));
        	pomr.setRh(ObjectUtils.getStrVal(map.get("rh")));
        	pomr.setRqlx(1);//
        	pomr.setWhcd(1);//
        	pomr.setXbm(ObjectUtils.getIntVal(map.get("xbm").toString()));
        	pomr.setXm(ObjectUtils.getStrVal(map.get("xm")));
        	pomr.setXx(1);//
        	pomr.setXzz(ObjectUtils.getStrVal(map.get("xzz")));
        	pomr.setXzzqwh(ObjectUtils.getStrVal(map.get("xzzqwh")));
        	pomr.setZjh(ObjectUtils.getStrVal(map.get("zjh")));
        	pomr.setZjlx(1);
        	pomr.setZplj(ObjectUtils.getStrVal(map.get("zplj")));
        	pomr.setZw(1);//
        	
        	pomrService.addPomr(pomr);
        }
        return b;
    }
	
	
}

